<style lang="less">
@import "../../styles/common.less";
</style>

<template>
  <div>
    <!-- <Spin size="large" fix v-if="spinShow" class="mask"></Spin> -->
    <Form :label-width="100">
      <Card>
        <p slot="title">专业设计栏目</p>
        <el-table
        :data="list1"
        border
        style="width: 100%">
            <el-table-column
            prop="title"
            label="标题"
            width="180">
            </el-table-column>

            <el-table-column
            prop="catePicUrl"
            label="图片"
            width="180">
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 100px"
                    :src="scope.row.catePicUrl"
                    
                    ></el-image>
                </template>
            </el-table-column>

            <el-table-column
            prop="iconPicUrl"
            label="图标">
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 100px; background-color: #000;"
                    :src="scope.row.iconPicUrl"
                    ></el-image>
                </template>
            </el-table-column>

            <el-table-column
            prop="productcateName"
            label="跳转分类">
            </el-table-column>

            <el-table-column
                fixed="right"
                label="编辑"
                width="100">
                <template slot-scope="scope">
                    <el-button type="text" @click="getIndexCateSetting(scope.row)" size="small">编辑</el-button>
                </template>
            </el-table-column>

            

        </el-table>
      </Card>
      

        <Card>
        <p slot="title">搜索房间栏目</p>
        <el-table
        :data="list2"
        border
        style="width: 100%">
            <el-table-column
            prop="title"
            label="标题"
            width="180">
            </el-table-column>

            <el-table-column
            prop="catePicUrl"
            label="图片"
            width="180">
                <template slot-scope="scope">
                    <el-image
                    style="width: 100px; height: 100px"
                    :src="scope.row.catePicUrl"
                    ></el-image>
                </template>
            </el-table-column>



            <el-table-column
            prop="productcateName"
            label="跳转分类">
            </el-table-column>

            <el-table-column
                fixed="right"
                label="编辑"
                width="100">
                <template slot-scope="scope">
                    <el-button type="text" @click="getIndexCateSetting(scope.row,'is')" size="small">编辑</el-button>
                </template>
            </el-table-column>

            

        </el-table>
      </Card>

        <Modal v-model="editModel" title="编辑">
		      <Form :model="editRow" :label-width="120" ref="editRow">
		        <FormItem label="标题" class="ivu-form-item-required">
		          <Input v-model="editRow.title" style="width:250px"></Input>
		        </FormItem>
		        <FormItem label="图片" class="ivu-form-item-required">
		          <div class="upload-list" v-if="editRow.catePicUrl">
		              <img :src="editRow.catePicUrl" />
		              <div class="upload-list-cover">
		                <Icon type="ios-eye-outline" @click.native="handleView(editRow.catePicUrl)"></Icon>
		                <Icon type="ios-trash-outline" @click.native="handleRemove(editRow.catePicUrl)"></Icon>
		              </div>
		          </div>
		          <Upload
		            ref="upload"
		            :show-upload-list="false"
		            :default-file-list="defaultList"
		            :on-success="handleSuccess"
		            :format="uploadImageFormat"
		            :max-size="uploadImageMaxSize"
		            :on-format-error="handleFormatError"
		            :on-exceeded-size="handleMaxSize"
		            :before-upload="handleBeforeUpload"
		            type="drag"
		            :action="actionName"
		            style="display: inline-block;width:58px;"
		          >
		            <div style="width: 58px;height:58px;line-height: 58px;">
		              <Icon type="camera" size="20"></Icon>
		            </div>
		          </Upload>
		          <div style="color:red">(建议上传封面图片分辨率323X443)</div>
		        </FormItem>
		         
            <FormItem label="图标" class="ivu-form-item-required" v-if="iconIs">
		          <div class="upload-list" v-if="editRow.iconPicUrl">
		              <img :src="editRow.iconPicUrl" />
		              <div class="upload-list-cover">
		                <Icon type="ios-eye-outline" @click.native="handleView(editRow.iconPicUrl)"></Icon>
		                <Icon type="ios-trash-outline" @click.native="handleRemove1(editRow.iconPicUrl)"></Icon>
		              </div>
		          </div>
		          <Upload
		            ref="upload"
		            :show-upload-list="false"
		            :default-file-list="defaultList"
		            :on-success="handleSuccess1"
		            :format="uploadImageFormat"
		            :max-size="uploadImageMaxSize"
		            :on-format-error="handleFormatError"
		            :on-exceeded-size="handleMaxSize"
		            :before-upload="handleBeforeUpload"
		            type="drag"
		            :action="actionName"
		            style="display: inline-block;width:58px;"
		          >
		            <div style="width: 58px;height:58px;line-height: 58px;">
		              <Icon type="camera" size="20"></Icon>
		            </div>
		          </Upload>
		          <div style="color:red">(建议上传封面图标分辨率40X40)</div>
		        </FormItem>

                <FormItem label="分类ID" class="ivu-form-item-required">
		          <Input v-model="editRow.productcateUuid" style="width:250px"></Input>
		        </FormItem>

		      </Form>
		      <div slot="footer">
		        <Button type="text" @click="editcancel">取消</Button>
		        <Button type="primary"  @click.native="editok('editRow')">确定</Button>
		      </div>
		</Modal>

        <Modal title="图片预览" v-model="isPreviewImage">
				<img :src="previewImageUrl" v-if="isPreviewImage" style="width: 100%" />
				<div slot="footer">
					<Button type="default" @click="isPreviewImage = false">关闭</Button>
				</div>
			</Modal>
    </Form>
  </div>
</template>

<script>
export default {
  data() {
    return {
        list1:[],
        list2:[],
        editModel:false,
        editRow:{},
        previewImageUrl:"",
        isPreviewImage:false,
        defaultList: [
            //品牌LOGO列表
        ],
        uploadImageFormat: ["jpg", "jpeg", "png"], //上传图片格式
        uploadImageMaxSize: 10240, //最大上传图片大小10M
        actionName: this.$http.defaults.baseURL + "admin/uploadMediaFile", //上传图片action
        iconIs:false
    };
  },
  methods: {
    handleView(url) {
        this.previewImageUrl = url;
        this.isPreviewImage = true;
    },
    handleRemove(file) {
        this.editRow.catePicUrl = '';
    },
    handleRemove1(){
        this.editRow.iconPicUrl = '';
    },
    handleSuccess(res, file) {
        console.log('上传成功')
        file.url = res.data[0];
        this.editRow.catePicUrl = file.url;
    },
    handleSuccess1(res, file) {
        console.log('上传成功')
        file.url = res.data[0];
        this.editRow.iconPicUrl = file.url;
    },
    handleBeforeUpload() {
		      
	},
    handleFormatError(file) {
        this.$Notice.warning({
        title: "文件格式错误",
        desc: "上传文件格式错误, 请选择jpg, jpeg 或 png的图片."
        });
    },
    handleMaxSize(file) {
        this.$Notice.warning({
        title: "文件过大",
        desc: "文件大小不能超过10M."
        });
    },
    getIndexCateSettingList(imdex) {
      this.$http
        .post("/getIndexCateSettingList", this.common.request({"type":imdex}))
        .then(
          response => {
              if(imdex==1){
                  this.list1=response.data.body.data.setttings;
                  console.log(this.list1)

              }else{
                  this.list2=response.data.body.data.setttings;
                  console.log(this.list2)
              }
          },
          response => {}
        );
    },
    getIndexCateSetting(msg,is){
        if(is){
          this.iconIs=false;
        }else{
          this.iconIs=true;
        }
        console.log(this.iconIs)
        this.$http
        .post("/getIndexCateSetting", this.common.request({"indexCateSettingUuid":msg.indexCateSettingUuid}))
        .then(
          response => {
              this.editRow=response.data.body.data;
              this.editModel=true;
              console.log(this.editRow )
          },
          response => {}
        );
    },
    editcancel(){
      this.editModel=false;
      this.getIndexCateSettingList(1);
      this.getIndexCateSettingList(2);
    },
    editok(){//修改的接口
      console.log(this.editRow)
      this.$http
        .post("/admin/updateIndexCateSetting", this.common.request(this.editRow))
        .then(
          response => {
              this.editModel=false;
              this.getIndexCateSettingList(1);
              this.getIndexCateSettingList(2);
              this.$Notice.success({
                title: "成功",
                desc: "已添加",
                duration: 2
              });
          },
          response => {}
        );
    }
  },
  created() {},
  mounted() {
      this.getIndexCateSettingList(1);
      this.getIndexCateSettingList(2);
  },
  destroyed() {}
};
</script>
<style>
.demo-upload-list {
  display: inline-block;
  width: 160px;
  height: 160px;
  text-align: center;
  line-height: 60px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  margin-right: 4px;
}
.demo-upload-list img {
  width: 100%;
  height: 100%;
}
.demo-upload-list-cover {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
}
#inputalss {
  margin: 0px 110px;
}
.demo-upload-list:hover .demo-upload-list-cover {
  display: block;
}
.demo-upload-list-cover i {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin: 60px 2px;
}
.titles {
  float: left;
  font-weight: 500;
  margin-right: 15px;
  letter-spacing: 1px;
}
.Submissioncss {
  margin-left: 30px;
}
.Button1 {
  height: 25px;
  width: 50px;
  text-align: center;
  line-height: 10px;
}
</style>
